#include "thread_handler.h"
#include "acceptConnect.h"

extern void *thread_Handle();

int acceptConnect(int sockfd)
{
    struct sockaddr_in caddr = {0};

    socklen_t clen = sizeof(caddr);

    printf("wait client connect....\n");

    int cfd = accept(sockfd, (struct sockaddr *)&caddr, &clen);
    if (-1 == cfd)
    {
        perror("accpet");
        exit(EXIT_FAILURE);
    }

    printf("cfd = %d", cfd);
    printf("client ip: %s, port: %d \n", inet_ntoa(caddr.sin_addr), ntohs(caddr.sin_port));

    pthread_t tid = 0;
    int err = pthread_create(&tid, NULL, thread_handler, &cfd);
    if (0 != err)
    {
        fprintf(stderr, "prhread_create: %s\n", strerror(err));
        exit(EXIT_FAILURE);
    }

    return cfd;
}

void *thread_Handle(void *arg)
{
    printf("测试\n");
}